package com.bawei.module_publish.weiget;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.RelativeLayout;
import android.widget.SeekBar;
import android.widget.TextView;

import com.bawei.module_publish.R;

/**
 * @author：lxy
 * @decription:
 * @time：2025/6/29
 */
public class IndicatorSeekBar extends RelativeLayout implements SeekBar.OnSeekBarChangeListener{

    private SeekBar seekBar;
    private TextView textView;

    public IndicatorSeekBar(Context context) {
        this(context,null);
    }

    public IndicatorSeekBar(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public IndicatorSeekBar(Context context, AttributeSet attrs, int defStyleAttr) {
        this(context, attrs, defStyleAttr,0);
    }

    public IndicatorSeekBar(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init();
    }

    private void init() {
        inflate(getContext(), R.layout.seekbar_indicator, this);
        seekBar = findViewById(R.id.indicatorSeekbar);
        textView = findViewById(R.id.indicatorTextview);
        seekBar.setOnSeekBarChangeListener(this);
    }

    @Override
    public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
        textView.setText(i + "%");
    }

    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {

    }

    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {

    }

    public int getProgress() {
        return seekBar.getProgress();
    }

    public void setProgress(int progress) {
        seekBar.setProgress(progress);
        textView.setText(progress + "%");
    }
}
